home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Examples / protoWoggles / protoWoggle2.wwModel / model.eve
Encoding:
Text File  |  1995-04-02  |  5.7 KB  |  168 lines

  1. ##############################
  2. ## the base head is just a sphere
  3. ## I didn't change the name to reflect the fact that I just grabbed
  4. ## this from Examples/WavesWorld/canonicalRIB
  5. #
  6. set sphere(surface) plastic
  7. set sphere(color) {1.0 0.0 0.0}
  8. set sphere(radius) 1.0
  9. EveCmd {set sphere(zMin) -$sphere(radius)}
  10. EveCmd {set sphere(zMax) $sphere(radius)}
  11. set sphere(thetaMax) 360.0
  12. set sphere(xTranslate) 0
  13. set sphere(yTranslate) 0
  14. set sphere(zTranslate) 0
  15. set sphere(xRotate) 0
  16. set sphere(yRotate) 0
  17. set sphere(zRotate) 0
  18.  
  19. #########################
  20. ## there are two eyes...
  21. ## eyes() is stuff that stays the same for both
  22. ## while eye() stuff is specialized for left and right
  23. #
  24. set eyes(surface) metal
  25. set eyes(xRotate) 0
  26. set eyes(xTranslate) 0
  27. EveCmd {set eyes(yTranslate) [expr {$sphere(radius) * .5}]}
  28. EveCmd {set eyes(zTranslate) [expr {$sphere(radius) * .5}]}
  29. set eyes(protrusion) .95
  30. set eyes(color) {1 1 1} 
  31. set eyes(xRotate) 0
  32. set eyes(yRotate) 15
  33.  
  34. set eye(volumePreservingScaleFactor) 1.5
  35. EveCmd {set eye(xScale) [expr 1./sqrt($eye(volumePreservingScaleFactor))]}
  36. EveCmd {set eye(yScale) $eye(volumePreservingScaleFactor)}
  37. EveCmd {set eye(zScale) [expr 1./sqrt($eye(volumePreservingScaleFactor))]}
  38. set eye(color) {1.0 1.0 1.0}
  39. set eye(percentageOfHead) .2
  40. EveCmd {set eye(radius) [expr {$eye(percentageOfHead) * $sphere(radius)}]}
  41. EveCmd {set eye(zMin) -$eye(radius)}
  42. EveCmd {set eye(zMax) $eye(radius)}
  43. set eye(thetaMax) 360.0
  44.  
  45.  
  46. set eye(xRotate) 10
  47. set eye(yRotate) 0
  48.  
  49. ##########################
  50. ## there are two pupils...
  51. #
  52. EveCmd {set pupil(radius) [expr {$eye(radius)*.5}]}
  53. set pupil(scale) 1.0
  54. set pupil(color) {0 0 0}
  55.  
  56. set state normal
  57.  
  58. loadControlPanel controls.nib
  59.  
  60. proc drawEyes {} {
  61.  
  62.   global sphere eyes eye pupil
  63.  
  64.  
  65.   ##########
  66.   AttributeBegin; Attribute identifier name Eyes
  67.     Surface $eyes(surface)
  68.     Translate eyes(xTranslate) eyes(xTranslate) eyes(zTranslate)
  69.     Color $eyes(color)
  70.     AttributeBegin; Attribute identifier name RightEye
  71.       Rotate $eyes(xRotate) 1 0 0
  72.       Rotate $eyes(yRotate) 0 1 0
  73.       AttributeBegin; Attribute identifier name EyeBall
  74.         Translate 0 \
  75.                   [expr {$sphere(radius)*sin(radians($eyes(xRotate)))}] \
  76.                   [expr {-$eyes(protrusion)*$sphere(radius)*cos(radians($eyes(xRotate)))}]
  77.         # make sure this scale happens inside each eye, as it needs to be about the eye's origin 
  78.         Scale $eye(xScale) $eye(yScale) $eye(zScale)
  79.         Rotate $eye(xRotate) 1 0 0
  80.         Rotate $eye(yRotate) 0 1 0
  81.         # each eye should rotate the opposite of the eyes(yRotate) 
  82.         # so that they always start off staring straight ahead
  83.         Rotate [expr {-1*$eyes(yRotate)}] 0 1 0
  84.         Sphere $eye(radius) [expr {-$eye(radius)}] $eye(radius) 360
  85.         ##########
  86.         AttributeBegin; Attribute identifier name Pupil
  87.           set xTrans 0.0
  88.           set yTrans 0.0
  89.           set zTrans [expr {-$eye(radius)*.7}]
  90.           AttributeBegin; Attribute identifier name PupilGeometry
  91.             Translate $xTrans $yTrans $zTrans
  92.             Scale $pupil(scale) $pupil(scale) $pupil(scale)
  93.             Color $pupil(color)
  94.             Sphere $pupil(radius) -$pupil(radius) $pupil(radius) 360 
  95.           endShape ;#PupilGeometry
  96.         endShape ;#Pupil
  97.       endShape ;#EyeBall
  98.     endShape ;#RightEye
  99.  
  100.     ##########
  101.     AttributeBegin; Attribute identifier name LeftEye
  102.       # each eye should rotate the opposite of the eyes(xRotate) so
  103.       # that they always start off staring straight ahead
  104.       Rotate $eyes(xRotate) 1 0 0
  105.       Rotate -$eyes(yRotate) 0 1 0
  106.       ##########
  107.       AttributeBegin; Attribute identifier name EyeBall
  108.         Translate 0 \
  109.                   [expr {$sphere(radius)*sin(radians($eyes(xRotate)))}] \
  110.                   [expr {-$eyes(protrusion)*$sphere(radius)*cos(radians($eyes(xRotate)))}]
  111.         # make sure this scale happens inside each eye, as it needs to be about the eye's origin 
  112.         Scale $eye(xScale) $eye(yScale) $eye(zScale)
  113.         Rotate $eye(xRotate) 1 0 0
  114.         Rotate $eye(yRotate) 0 1 0
  115.         # each eye should rotate the opposite of the eyes(yRotate) so 
  116.         # that they always start off staring straight ahead
  117.         Rotate $eyes(yRotate) 0 1 0
  118.         Sphere $eye(radius) [expr {-$eye(radius)}] $eye(radius) 360
  119.         ##########
  120.         AttributeBegin; Attribute identifier name Pupil
  121.           set xTrans 0.0
  122.           set yTrans 0.0
  123.           set zTrans [expr {-$eye(radius)*.7}]
  124.           AttributeBegin; Attribute identifier name PupilGeometry 
  125.             Translate $xTrans $yTrans $zTrans
  126.             Scale $pupil(scale) $pupil(scale) $pupil(scale)
  127.             Color $pupil(color)
  128.             Sphere $pupil(radius) -$pupil(radius) $pupil(radius) 360 
  129.           endShape ;#PupilGeometry
  130.         endShape ;#Pupil
  131.       endShape ;#EyeBall
  132.     endShape ;#RightEye
  133.   endShape ;#Eyes
  134. }
  135.  
  136. # state: scared normal aggressive
  137. proc protoWoggle {state c xT yT zT xR yR zR} {
  138.  
  139.   global sphere
  140.  
  141.   set sphere(volumePreservingScaleFactor) 1
  142.   if {![string compare $state scared]} {  set sphere(volumePreservingScaleFactor) .8} {} 
  143.   if {![string compare $state aggressive]} {  set sphere(volumePreservingScaleFactor) 1.2} {} 
  144.  
  145.   set xS [expr 1./sqrt($sphere(volumePreservingScaleFactor))]
  146.   set yS $sphere(volumePreservingScaleFactor)
  147.   set zS [expr 1./sqrt($sphere(volumePreservingScaleFactor))]
  148.  
  149.   AttributeBegin; Attribute identifier name wwWoggle
  150.     Surface plastic
  151.     Color $c
  152.     Scale $xS $yS $zS
  153.     Translate $xT $yT $zT
  154.     Rotate $xR 1 0 0
  155.     Rotate $yR 0 1 0 
  156.     Rotate $zR 0 0 1
  157.     Sphere 1 -1 1 360
  158.     drawEyes
  159.   endShape
  160. }
  161.  
  162. startShape AProtoWoggle
  163.   animatable: {protoWoggle $state \
  164.                            $sphere(color) \
  165.                            $sphere(xTranslate) $sphere(yTranslate) $sphere(zTranslate) \
  166.                            $sphere(xRotate) $sphere(yRotate) $sphere(zRotate)}
  167. endShape
  168.